# -*- coding: utf-8 -*-


import mod.server.extraServerApi as serverApi

from enchantBase import EnchantBase

comp = serverApi.GetEngineCompFactory()


class RoseThorn(EnchantBase):
    def __init__(self, system, playerId, enchantData, levels):
        EnchantBase.__init__(self, system, playerId, enchantData, levels)

    def onEnter(self):
        self.mSystem.ListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(), 'ActuallyHurtServerEvent', self, self.burning)

    def onExit(self):
        self.mSystem.UnListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(), 'ActuallyHurtServerEvent', self, self.burning)

    def isArmorEnchant(self):
        return True

    def burning(self, args):
        src_id = args['srcId']
        entity_id = args['entityId']
        if entity_id != self.playerId:
            return
        if entity_id == src_id:
            return
        if src_id:
            max_level = max(self.levels)
            total_level = 0
            for i in self.levels:
                total_level += i
            comp_attr = comp.CreateAttr(src_id)
            comp_attr.SetEntityOnFire(max_level, total_level / 2)
            # print '[Debug] levels: {}, total: {}'.format(self.levels, total_level)
        pass
